import {promisifyAll} from 'miniprogram-api-promise'
const wxp = wx.p = {}
promisifyAll(wx, wxp);
import {checkSessionLogin} from "./services/login.js"

App({
  globalData: {
    screenWidth: 0,
    screenHeight: 0,
    menuBtnTop: 0,
    menuBtnHeight: 0,
    isMuted: false,
    videoDuration: 0,
    isReadScrollTip: false
  },
  onLaunch() {
    this.getMenuButtonAndScreenInfo();
    checkSessionLogin()
  },
  async getMenuButtonAndScreenInfo() {
    try {
      // 获取系统信息，包含屏幕宽高
      const windowInfo = await wx.p.getWindowInfo();
      const screenWidth = windowInfo.windowWidth;
      const screenHeight = windowInfo.windowHeight;
      // 获取右上角胶囊位置信息
      const menuButtonRect = await wx.p.getMenuButtonBoundingClientRect();
      // 将获取到的信息存储到 globalData 中
      this.globalData.rpxWidth = screenWidth / 750;
      this.globalData.screenHeight = screenHeight;
      this.globalData.menuBtnTop = menuButtonRect.top;
      this.globalData.menuBtnHeight = menuButtonRect.height;
      console.log("获取页面位置信息完成")
    } catch (error) {
      console.log("获取页面位置信息失败")
      this.showNetError()
    }
  },
  async showNetError() {
    return await wx.showModal({
      title: '网络波动',
      content: '请您刷新小程序重试',
      showCancel: false
    })
  }
})